import { FormControl } from '@angular/forms';

export enum NodeType {
  folder = 'folder',
  table = 'table'
}

export interface FolderNode {
  title: string;
  key: string;
  id: string;
  pid: string | undefined;
  type: string;
  name: string;
  workspaceId: number;
  remark: string;
  children?: [];
}

export enum ImportType {
  SQL = 0,
  JSON = 1,
  EXCEL = 2,
  DATABASE = 3
}

export enum OptType {
  addRootNode = 'addRootNode',
  addNode = 'addNode',
  addTable = 'addTable',
  rename = 'rename'
}

export enum SourceType {
  input = 'input',
  excel = 'excel',
  json = 'json',
  sql = 'sql',
  database = 'database',
  clone = 'clone'
}

export const DbTypes: any[] = ['mysql', 'oracle', 'postgresql', 'sqlserver', 'maxcompute1', 'clickhouse', 'flink'];

// 适配druid DbType类型
export const DruidDbTypes: any[] = [
  { value: 'mysql', label: 'mysql, mariadb, drds' },
  { value: 'oracle', label: 'oracle, oceanbase_oracle' },
  { value: 'postgresql', label: 'postgresql, hologres, edb' },
  { value: 'sqlserver', label: 'sqlserver, jtds' },
  { value: 'maxcompute1', label: 'maxcompute1.*, maxcompute2.*' },
  { value: 'clickhouse', label: 'clickhouse' },
  { value: 'flink', label: 'flink, blink' }
];

export const DataTypes: any[] = ['char', 'varchar', 'float', 'double', 'decimal'];

export const ConstraintTypes: any[] = [
  { name: '主键', value: 'pk' },
  { name: '唯一索引', value: 'uin' },
  { name: '普通索引', value: 'in' }
];

export interface ColumnForm {
  columnName: FormControl<string>;
  columnComment: FormControl<string | ''>;
  dataType: FormControl<string>;
  length: FormControl<string | null>;
  scale: FormControl<string | null>;
  nullable: FormControl<boolean>;
  dataDefault: FormControl<string | null>;
  // columnOrder: FormControl<string>;
  // remark: FormControcl<string>;
}

export interface ConstraintForm {
  constraintType: FormControl<string>;
  constraintName: FormControl<string>;
  columnList: FormControl<any[]>;
  pkAutoIncrement: FormControl<boolean>;
}

export const CONST_COLUMNS: any = {
  id: {
    columnName: 'id',
    columnComment: '主键',
    dataType: 'bigint',
    length: '',
    scale: '',
    nullable: true,
    dataDefault: ''
  },
  createdBy: {
    columnName: 'created_by',
    columnComment: '创建人',
    dataType: 'varchar',
    length: '255',
    scale: '',
    nullable: true,
    dataDefault: ''
  },
  createdDate: {
    columnName: 'created_date',
    columnComment: '创建日期',
    dataType: 'datetime',
    length: '',
    scale: '',
    nullable: true,
    dataDefault: ''
  },
  lastModifiedBy: {
    columnName: 'last_modified_by',
    columnComment: '更新人',
    dataType: 'varchar',
    length: '255',
    scale: '',
    nullable: true,
    dataDefault: ''
  },
  lastModifiedDate: {
    columnName: 'last_modified_date',
    columnComment: '更新日期',
    dataType: 'datetime',
    length: '',
    scale: '',
    nullable: true,
    dataDefault: ''
  }
};
